using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.FaceBook.Scene;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class UnbindFaceBook : BasePage
	{
		private const string TAG = "UnbindFaceBook";
		private string currentToken = "";
		private EventWatcher bindWatcher;
		internal Grid LayoutRoot;
		internal TextBlock PageTitle;
		internal Button ViewFriends;
		internal Button UnbindFB;
		private bool _contentLoaded;
		public static void ShowUnbindFaceBookPage(BasePage originPage, string strToken)
		{
			originPage.GoToPage("/Source/Plugin/Facebook/UI/UnbindFaceBook.xaml", new object[]
			{
				strToken
			}, false);
		}
		public UnbindFaceBook()
		{
			this.InitializeComponent();
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && Enumerable.Count<object>(object_0) > 0)
			{
				this.currentToken = (object_0[0] as string);
				this.InitBind();
				return;
			}
		}
		protected override void OnPageOut()
		{
			this.UnitBind();
		}
		private void ViewFriends_Click(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("UnbindFaceBook", "ViewFriends_Click");
			Account curAccount = AccountMgr.getCurAccount();
			if (string.IsNullOrEmpty(curAccount.FBToken))
			{
				return;
			}
			FaceBookFriends.ShowFaceBookFriendsPage(this, curAccount.FBToken, true);
		}
		private void UnbindFB_Click(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("UnbindFaceBook", "UnbindFB_Click");
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.FaceBookUnbindInfo, strings.FaceBookUnbindAlert, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnUnbindFBtHandler);
		}
		private void OnUnbindFBtHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
			{
				Log.smethod_5("UnbindFaceBook", " netSceneFaceBookAuth.doScene");
				this.showProgressCover(strings.FaceBookUnBinding);
				NetSceneFaceBookAuth netSceneFaceBookAuth = new NetSceneFaceBookAuth();
				netSceneFaceBookAuth.doScene(0, this.currentToken);
				break;
			}
			case 1:
				break;
			default:
				return;
			}
		}
		private void InitBind()
		{
			this.bindWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onBindEvent));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_FACEBOOK_EVENT, this.bindWatcher);
		}
		private void UnitBind()
		{
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_FACEBOOK_EVENT, this.bindWatcher);
		}
		private void onBindEvent(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.hideProgressCover();
			if (evtArgs == null)
			{
				return;
			}
			FBAuthRet fBAuthRet = evtArgs.mObject as FBAuthRet;
			if (fBAuthRet == null)
			{
				return;
			}
			if (fBAuthRet.opType == 2)
			{
				return;
			}
			Log.smethod_5("UnbindFaceBook", string.Concat(new object[]
			{
				"onBindEvent:",
				fBAuthRet.mIsSuccess,
				",ret.mRetCode",
				fBAuthRet.mRetCode
			}));
			if (fBAuthRet.mIsSuccess)
			{
				MMMessageBox.Show(strings.FaceBookUnbindSuccess, true, "确定");
				base.GoBack();
				return;
			}
			if (fBAuthRet.mRetCode == RetConst.MM_ERR_CLIENT)
			{
				MMMessageBox.Show(strings.FaceBookUnbindNetInfo, true, "确定");
				return;
			}
			if (fBAuthRet.mRetCode == RetConst.MM_ERR_ACCESS_DENIED)
			{
				MMMessageBox.Show(strings.FaceBookUnBindErrorInfo, true, "确定");
				return;
			}
			MMMessageBox.Show(strings.FaceBookUnbindRetry, true, "确定");
		}
		private void showProgressCover(string strCoverTitle)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, null, false, false, null);
		}
		private void hideProgressCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Facebook/UI/UnbindFaceBook.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.PageTitle = (TextBlock)base.FindName("PageTitle");
			this.ViewFriends = (Button)base.FindName("ViewFriends");
			this.UnbindFB = (Button)base.FindName("UnbindFB");
		}
	}
}
